/*
 * Vector3 class for 3D vector calculations.
 */

package vectorsdk;

/**
 *
 * @author menderleit
 */
public class Vector3 implements Comparable {
    private double x, y, z;

    // Contstructors.
    public Vector3() {
        x = 0.0;
        y = 0.0;
        z = 0.0;
    }
    public Vector3(double X, double Y, double Z) {
        x = X;
        y = Y;
        z = Z;
    }
    public Vector3(Vector3 vec) {
        x = vec.x();
        y = vec.y();
        z = vec.z();
    }
    
    public void setPos(double X, double Y, double Z) {
        x = X;
        y = Y;
        z = Z;
    }
    public double x() {
        return x;
    }
    public double y() {
        return y;
    }
    public double z() {
        return z;
    }
    public Vector3 copy() {
        Vector3 vec = new Vector3(this);
        return vec;
    }
    // Returns the dot-product. ( this . vec )
    public Vector3 dot(Vector3 vec) {
        Vector3 dotvec = new Vector3(x * vec.x(), y * vec.y(), z * vec.z());
        return dotvec;
    }
    public Vector3 normalize() {
        double len = length();
        Vector3 normal = new Vector3(x/len, y/len, z/len);
        return normal;
    }
    public double length() {
        double len = Math.sqrt((x*x)+(y*y)+(z*z));
        return len;
    }

    @Override
    public int compareTo(Object t) {
        Vector3 o = (Vector3)t;
        if(o.z < z) return -1;
        if(o.z > z) return 1;
        return 0;
    }
}
